﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntraVision.Web;

namespace Model
{
    public enum EventLogOperationType
    {
        UserLogin = 1
        ,UserLogout = 2
        ,ClientLogin = 3
        ,ClientLogout = 4
    }

    partial class EventLog
    {
        public static void AddToLog(int? userId, int? personId, string ip, EventLogOperationType operation)
        {
            try 
            {
                using (var dc = new NotarialServiceDataContext())
                {
                    dc.EventLogs.InsertOnSubmit(new EventLog(userId, personId, ip, operation));
                    dc.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Ошибка при добавление записи в лог событий: {0}", ex.Message));
            }
            
        }

        public EventLog(int? userId, int? personId, string ip, EventLogOperationType operation)
        {
            this.UserId = userId;
            this.PersonId = personId;
            this.Ip = ip;
            this.Date = DateTime.Now;
            this.OperationId = (int)operation;
        }
    }
}
